﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.world.machines {
    import flash.events.*;
    import flash.display.*;
    import flash.text.*;
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.utils.*;

    public class SlotMachineView extends AbstractMachineView {

        private var m_iconHolder:Sprite;
        private var m_reels:Array;
        private var timer:Timer;

        private static const NUM_SLOTS:int = 3;
        private static const REEL_ANIMATION_INTERVAL:int = 300;

        public function SlotMachineView(_arg1:String, _arg2:MovieClip){
            this.m_reels = [];
            super(_arg1, _arg2);
        }
        override protected function onChildrenCreated():void{
            super.onChildrenCreated();
            this.m_iconHolder = new Sprite();
            this.m_iconHolder.x = (this.m_iconHolder.x - ((content.width >> 1) - 90));
            this.m_iconHolder.y = (this.m_iconHolder.y - ((content.height >> 1) - 50));
            content.addChild(this.m_iconHolder);
            this.stopMovies();
            content.buttonMode = true;
        }
        public function setCoinAnimationText(_arg1:String):void{
            var _local2:TextFormat = new TextFormat();
            _local2.font = "ShowcardGothic";
            content.textTween.rewardText.tf.embedFonts = true;
            content.textTween.rewardText.tf.htmlText = _arg1;
            content.textTween.rewardText.tf.autoSize = TextFieldAutoSize.CENTER;
            content.textTween.rewardText.tf.multiline = false;
            content.textTween.rewardText.tf.setTextFormat(_local2);
        }
        public function handleAnimation(_arg1:String):void{
            switch (_arg1){
                case WorldConstants.IDLE:
                    this.stopMovies();
                    break;
                case WorldConstants.BUSY:
                    this.startRolling();
                    break;
            };
        }
        private function startRolling():void{
            this.cleanOutIcons();
            content.slot_1.gotoAndStop("Fast");
            content.slot_2.gotoAndStop("Fast");
            content.slot_3.gotoAndStop("Fast");
            content.bulb.gotoAndStop("active");
            content.handle.gotoAndStop("active");
            content.alarm.gotoAndStop("active");
            content.textTween.gotoAndPlay("start");
        }
        private function stopMovies():void{
            content.bulb.gotoAndStop("inactive");
            content.handle.gotoAndStop("inactive");
            content.slot_1.gotoAndStop("Stop");
            content.slot_2.gotoAndStop("Stop");
            content.slot_3.gotoAndStop("Stop");
            content.alarm.gotoAndStop("inactive");
            content.textTween.gotoAndStop("stop");
        }
        public function renderResult(_arg1:Array):void{
            var _local2:String;
            var _local3:MovieClip;
            var _local4:int;
            while (_local4 < _arg1.length) {
                _local2 = ("SlotIcon" + _arg1[_local4]);
                _local3 = AssetsLibrary.getMovieClip(_local2);
                this.m_reels[_local4] = _local3;
                _local4++;
            };
            this.addTimer();
        }
        private function cleanOutIcons():void{
            var _local1:int;
            while (_local1 < NUM_SLOTS) {
                Displays.removeChild(DisplayObject(this.m_reels[_local1]));
                this.m_reels[_local1] = null;
                _local1++;
            };
        }
        private function addIcons(_arg1:TimerEvent):void{
            var _local2:Object;
            if (_arg1.type == TimerEvent.TIMER){
                switch (this.timer.currentCount){
                    case 1:
                        content.slot_1.gotoAndStop("Slow");
                        break;
                    case 2:
                        content.slot_1.gotoAndStop("Stop");
                        content.slot_2.gotoAndStop("Slow");
                        content.symbol_0.addChild(this.m_reels[0]);
                        break;
                    case 3:
                        content.slot_2.gotoAndStop("Stop");
                        content.slot_3.gotoAndStop("Slow");
                        content.symbol_1.addChild(this.m_reels[1]);
                        break;
                    case 4:
                        content.slot_3.gotoAndStop("Stop");
                        content.bulb.gotoAndStop("inactive");
                        content.handle.gotoAndStop("inactive");
                        content.alarm.gotoAndStop("inactive");
                        content.symbol_2.addChild(this.m_reels[2]);
                        _local2 = {event:SlotMachineEvent.ON_SLOT_MACHINE_UPDATED};
                        dispatchEvent(new InfoEvent(EventConstants.HANDLE_ACTION, id, _local2));
                        dispatchEvent(new InfoEvent(EventConstants.SLOTMACHINE_ANIMATION_FINISHED, null));
                        this.recycleTimer();
                        break;
                };
            };
        }
        private function addTimer():void{
            this.timer = ((this.timer) || (new Timer(REEL_ANIMATION_INTERVAL, 4)));
            this.timer.addEventListener(TimerEvent.TIMER, this.addIcons);
            this.timer.start();
        }
        private function recycleTimer():void{
            this.timer.removeEventListener(TimerEvent.TIMER, this.addIcons);
            this.timer.reset();
        }
        public function playAnimation(_arg1:String):void{
            if (content[_arg1]){
                MovieClip(content[_arg1]).play();
            };
        }

    }
}//package net.wooga.pets.views.world.machines 
